const isProduction = process.env.NODE_ENV === 'production';
const webpack = require('webpack');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];
const { name } = require('./package');
module.exports = {
  //路径前缀
  publicPath: "/cqjj",
  // lintOnSave: !isProduction,
  lintOnSave:false,
  productionSourceMap: !isProduction,
  chainWebpack: (config) => {
    //忽略的打包文件
    config.externals({
      'vue': 'Vue',
      'vue-router': 'VueRouter',
      'vuex': 'Vuex',
      'axios': 'axios',
      'element-ui': 'ELEMENT',
    });
    //config.module.rule('fonts').use('url-loader').loader('url-loader').options({}).end();
    //config.module.rule('images').use('url-loader').loader('url-loader').options({}).end();
    // const entry = config.entry('app');
    // entry.add('babel-polyfill').end();
    // entry.add('classlist-polyfill').end();
    // entry.add('@/mock').end();
  },
  configureWebpack: {
    name:name,
    output: {
        library: `${name}-[name]`,
        libraryTarget: 'umd',
        jsonpFunction: `webpackJsonp_${name}`,
        // globalObject: 'this',   // here
    },
    plugins: [
        // Ignore all locale files of moment.js
        new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
        // 配置compression-webpack-plugin压缩
        new CompressionWebpackPlugin({
            algorithm: 'gzip',
            test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
            threshold: 10240,
            minRatio: 0.8
        }),
        new webpack.optimize.LimitChunkCountPlugin({
            maxChunks: 5,
            minChunkSize: 100
        })
    ]
  },
  //开发模式反向代理配置，生产模式请使用Nginx部署并配置反向代理
  devServer: {
    port: 8080,
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      '/api': {
        // target: 'http://127.0.0.1:7880',
        //target: 'http://192.168.3.57:7880',//联调直连ip端口
        target: 'http://cqjj.sxwise.com/api',// 访问测试环境接口
        ws: true,
        pathRewrite: {
          '^/api': '/'
        }
      },
    }
  }
};

